9. UC-SLS Lecture 9 : Assembly : Operations and Data Types

9.1. A simple mov.S program

9.1.1. Setup

  • create a directory mkdir mov; cd mov

  • create and write mov.S below

  • add a Makefile to automate assembling and linking

    • we are going run the commands by hand this time to highlight the details

  • add our setup.gdb to make working in gdb easier

  • normally you would want to track everything in git

CODE: asm - mov.S

	.intel_syntax noprefix
	.text
	
	.equ EXIT_SYSCALL_NR,60
	
	.global _start
	.type _start, @function	
_start:
	mov rax, 0b1000

	mov rax, EXIT_SYSCALL_NR
	mov rdi, 2
	syscall
	
	

9.1.2. Assemble mov.S into mov.o directly with assembler (as)

  • -a produce listing to standard out

  • we could add -g flag to add extra debugger information but lets skip it for now

rm: cannot remove 'mov.o': No such file or directory
as  -a=mov.o.lst mov.S -o mov.o

9.1.2.1. mov.o is NOT an executable

$ ls -l mov.o
-rw-r--r-- 1 jovyan root 752 Nov  4 16:31 mov.o

9.1.2.2. What kind of file is is it?

$ file mov.o
mov.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

9.1.2.3. Examine Symbol Table

$ objdump -t mov.o

mov.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    d  .text	0000000000000000 .text
0000000000000000 l    d  .data	0000000000000000 .data
0000000000000000 l    d  .bss	0000000000000000 .bss
000000000000003c l       *ABS*	0000000000000000 EXIT_SYSCALL_NR
0000000000000000 g     F .text	0000000000000000 _start

9.1.4. gdb -tui mov -x setup.gdb

9.1.4.1. rebuild with more debug info -g

rm -f mov mov.o mov.o.lst mov.map
as -g -a=mov.o.lst mov.S -o mov.o
ld -g -Map=mov.map mov.o -o mov

Debug

By Jonathan Appavoo
© Copyright 2021.